<template>
	<!-- 地方馆 -->
	<view style="width: 100%; height: auto; min-height: 1320rpx; background-color: pink;">
		<view class="bgc">
			<!-- <p>接收到的数据：{{ receivedData }}</p> -->
			<!-- top -->
			<view class="top">
				<scroll-view scroll-x="true" scroll-y="true" enable-flex="true">
					<view style="display: flex;">
						<view class="top_box" v-for="(item,index) in cityList" :key="index" @click="changeTab(item.value,item.label)">
							<view style="height: 100rpx; width: 100rpx;" :class="selCityName==item.label?'box_img':''">
								<image :src="item.icon" mode="scaleToFill"
									style="height: 100%;width: 100%;border-radius: 50%;"></image>
							</view>
							<view :class="selCityName==item.label?'box_font':''"><text>{{item.name}}</text></view>
						</view>
					</view>
				</scroll-view>
			</view>
			<!-- 中间区域 -->
		
			<view class="body_gbc">
				<!-- 左侧滚动条 -->
				<scroll-view scroll-y="true" class="body_left">
					<view style="display: flex;flex-direction: column;">
						<text :class="selAreaName==item.name?'left_box red':'left_box'" v-for="(item,index) in areaList" :key="index" @click="changeArea(item.value,item.name)">{{item.name}}</text>
					
					</view>
				</scroll-view>
		
				<!-- 右侧滚动栏 -->
				<scroll-view scroll-y="true" class="body_right">
					<block v-if="goodsList.length>0">
						<view class="right_box"  v-for="(item,index) in goodsList" :key="index" @click="goodsDesc(item.id)">
							<view class="right_box_left">
								<image :src="item.image" mode="scaleToFill" style="width: 100%;height: 100%;"></image>
							</view>
							<view class="right_box_right">
								<text style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;lines:1;font-weight: 700;">{{item.title}}</text>
								<view style="display: flex;justify-content: space-between;">
									<text style="font-size: 26rpx; color: #a9a9a9;">销量：{{item.sales}}</text>
									<text class="click_">￥{{item.price}}</text>
								</view>
							</view>
						</view>
				</block>
				<view v-else style="text-align: center;color: #bcbcbc;margin-top: 30rpx;">暂无更多产品</view>
				</scroll-view>
			</view>

			<!-- </view> -->

		</view>
	</view>
</template>

<script>
	export default {
	
		data() {
			return {
				cityList:[],
				selCityName:'',
				areaList:[],
				selAreaName:'',
				goodsList:[],
				page:1,
				limit:10,
				total:0
			}
		},
		onLoad(options){
			this.selCityName = decodeURIComponent(options.name);
			this.getCity();
		},
		onReachBottom() {
			if(this.goodsList.length<this.total){
				this.getGoodsList(this.selCityName,this.selAreaName)
			}
		},
		onHide() {
			this.page = 1;
			this.goodsList = [];
		},
		methods: {
			//获取城市
			getCity(){
				var _this = this;
				_this.$http('apply.getCityList',{}).then(res=>{
					_this.cityList = res.data;
					_this.cityList.forEach(item=>{
						if(item.label == _this.selCityName){
							_this.getAreaList(item.value);
						}
					})
				})
			},
			//获取地区
			getAreaList(value){
				var _this = this;
				_this.$http('apply.getAreaList',{
					id:value,
				}).then(res=>{
					_this.areaList = res.data;
					_this.selAreaName = res.data[0]['name'];
					_this.getGoodsList(_this.selCityName+'市',_this.selAreaName);
				})
			},
			//获取商品
			getGoodsList(cityName,areaName){
				var _this = this;
				_this.$http('apply.getGoodsList',{
					cityName:cityName,
					areaName:areaName,
					page:_this.page,
					limit:_this.limit,
				}).then(res=>{
					_this.goodsList = _this.goodsList.concat(res.data.list);
					_this.total = res.data.total;
					_this.page++;
				})
			},
			changeTab(value,label){
				this.selCityName = label;
				this.page = 1;
				this.goodsList = [];
				this.getAreaList(value);
			},
			changeArea(value,label){
				this.selAreaName = label;
				this.page = 1;
				this.goodsList = [];
				this.getGoodsList(this.selCityName+'市',label);
			},
			goodsDesc(id){
				uni.navigateTo({
					url:'/pages/goods/detail?id='+id
				})
			}
		}
	}
</script>

<style lang="scss">
	.bgc {
		background-color: #fff;
		// padding: 0 20rpx 0 20rpx;

		.top {
			background-color: #fff;
			width: 100%;
			height: 14vh;
			// background-color: skyblue;
			// padding: 0 20rpx 0 20rpx;
			font-size: 24rpx;

			.top_box {
				margin: 30rpx 15rpx 0 15rpx;
				// background-color: bisque;
				width: 200rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				// margin-right: 20rpx;
				.box_img {
					border: 2px solid red;
					border-radius: 50%;
				}

				.box_font {
					margin-top: 5rpx;
					background-color: #e34135;
					height: 40rpx;
					width: 100rpx;
					line-height: 40rpx;
					text-align: center;
					border-radius: 50rpx;
					color: #fff;
				}
			}
		}

		.body_gbc {
			background-color: #fff;
			height: 80%;
			display: flex;
			// padding: 0 20rpx 0 0rpx;
			height: 86vh;
			
			.body_left {
				width: 25%;
				background-color: #fff;
				// display: flex;
				// flex-direction: column;
				.left_box {
					display: flex;
					height: 90rpx;
					width: 100%;
					padding-left: 30rpx;
					font-size: 27rpx;
					align-items: center;
					
				}
				.red {
					color: red;
					background-color: #f1f1f1;
				}
			}
			.body_right {
				width: 75%;
				background-color: #f1f1f1;
				padding: 20rpx;
				padding-top: 0;
				.right_box {
					margin: 20rpx 0 20rpx 0;
					display: flex;
					align-items: center;
					height: 200rpx;
					width: 100%;
					background-color: #fff;
					border-radius: 10rpx;
					
					.right_box_left {
						height: 100rpx;
						width: 100rpx;
						margin: 0 20rpx;
					}
					.right_box_right {
						height: 100%;
						width: 350rpx;
						display: flex;
						padding: 30rpx 40rpx 40rpx 10rpx;
						flex-direction: column;
						justify-content: space-between;
						.click_ {
							height: 40rpx;
							width: 120rpx;
							border-radius: 60rpx;
							color: red;
							// border: 2rpx solid red;
							background-color: #fff;
							text-align: center;
							line-height: 40rpx;
							font-size: 26rpx;
						}
					}
				}
				
			
			}
		}
	
	}
</style>